use UMAS0007b_OUTPUT.dta, clear


*** Marathon Questions ***
recode Q17_1-Q17_8 (2=0)

svyset [pw=weight]

*Concern about Terrorism*
svy: tab Q18
svy: tab Q18 if region==1 
svy: tab Q18 if region==2

*Increased Spectators*
svy: tab Q19
svy: tab Q19 if region==1 
svy: tab Q19 if region==2

*Punishment of Bombers*
svy: tab Q20a
svy: tab Q20a if region==1 
svy: tab Q20a if region==2

svy: tab Q20b
svy: tab Q20b if region==1 
svy: tab Q20b if region==2


*Security Measures*
svy: mean Q17_1-Q17_8




***New code for zip code of boston area***

*Generate and drop extra zipcode*

gen zipcode=real(lookupzip)

sort zipcode
merge zipcode using "zcta_cbsa_rel_10.dta"
drop if _m<3

*Generate Regions*
gen region=1 if cbsa==14460
replace region=2 if cbsa==12700 | cbsa==39300
replace region=3 if cbsa==49340
replace region=4 if cbsa==38340 | cbsa==44140
label define region 1 "Boston Area" 2 "New Bedford/Cape Cod" 3 "Central MA" 4 "Western MA"
label values region region

*Generate Boston area and Rest of MA*
gen region2=1 if region==1
replace region2=2 if region>1
label define region2 1 "Boston Area" 2 "Rest of MA"
label values region2 region2




**Crosstabs**

*Income Recode*
gen incomecat=1 if faminc<=4
replace incomecat=2 if faminc>4 & faminc<10
replace incomecat=3 if faminc<97 & faminc>10

label define incomecat 1 "Less than $40k" 2 "$40k - $100k" 3 "Over $100k"
label values incomecat incomecat

*Ideology Recode*
gen ideo3=ideo5
recode ideo3 1/2=1 3=2 4/5=3 6=4
label define ideo3 1 "liberal" 2 "moderate" 3 "conservative"
label val ideo3 ideo3
label var ideo3 "Ideology 3 point"

*Party ID Recode*
recode pid3 4/5=3

*Age Recode*
gen age=2013-birthyr
gen agecat=1 if age<30
replace agecat=2 if age>29 & age<55
replace agecat=3 if age>54

label define agecat 1 "18-29" 2 "30-54" 3 "55+"
label values agecat agecat

*Race Recode*
recode race 5/9=., gen(racecat)
replace racecat=3 if hispanic==1

*Education Recode*
recode educ 1/2=1 3=2 4/5=3 6=4, gen(educcat)
label define educcat 1 "HS or less" 2 "Some college" 3 "College degree" 4 "Postgraduate"
label values educcat educcat




*Recodes for 1/0 for crosstabs*

recode Q1 2/3=0, gen(USrighttrack)
tablemat USrighttrack [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q1 2=1 1=0 3=0, gen(USwrongtrack)
tablemat USwrongtrack [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3) st(mean)

recode Q2 2/3=0, gen (MArighttrack)
tablemat MArighttrack [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q2 2=1 1=0 3=0, gen(MAwrongtrack)
tablemat MAwrongtrack [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q20a 2/3=0, gen (TsarnaevDP) 
tablemat TsarnaevDP [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q20a 2=1 1=0 3=0, gen (TsarnaevLP)
tablemat TsarnaevLP [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)


recode Q20b 2/3=0, gen (DeathPenalty)
tablemat DeathPenalty [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q20b 2=1 1=0 3=0, gen (LifeParole)
tablemat LifeParole [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)


*Warren = 1, already 1/0 between Warren and Markey*

recode Q10 1=1 2=0, gen(SenRep)  
tablemat SenRep [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q11 1=1 2=0, gen(SenEffect)
tablemat SenEffect [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)


*Markey Present*

recode Q16 1=1 2=1 3=0 4=0 5=0, gen(MarkeyPresentSupport)
tablemat MarkeyPresentSupport [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q16 1=0 2=0 3=1 4=1 5=0, gen(MarkeyPresentOppose)
tablemat MarkeyPresentOppose [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)


*Senator Traits*
gen comp_warren = Q15a
recode comp_warren 1=1 2/4=0

gen comp_markey = Q15a
recode comp_markey 2=1 1=0 3/4=0

gen comp_neither = Q15a
recode comp_neither 3=1 1/2=0 4=0

tablemat comp_warren comp_markey comp_neither [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3) st(mean)


gen intg_warren = Q15b
recode intg_warren 1=1 2/4=0

gen intg_markey = Q15b
recode intg_markey 2=1 1=0 3/4=0

gen intg_neither = Q15b
recode intg_neither 3=1 1/2=0 4=0

tablemat intg_warren intg_markey intg_neither [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3) st(mean)


gen lead_warren = Q15c
recode lead_warren 1=1 2/4=0

gen lead_markey = Q15c
recode lead_markey 2=1 1=0 3/4=0

gen lead_neither = Q15c
recode lead_neither 3=1 1/2=0 4=0

tablemat lead_warren lead_markey lead_neither [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3) st(mean)


gen acc_warren = Q15d
recode acc_warren 1=1 2/4=0

gen acc_markey = Q15d
recode acc_markey 2=1 1=0 3/4=0

gen acc_neither = Q15d
recode acc_neither 3=1 1/2=0 4=0

tablemat acc_warren acc_markey acc_neither [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3) st(mean)


gen emp_warren = Q15e
recode emp_warren 1=1 2/4=0

gen emp_markey = Q15e
recode emp_markey 2=1 1=0 3/4=0

gen emp_neither = Q15e
recode emp_neither 3=1 1/2=0 4=0

tablemat emp_warren emp_markey emp_neither [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3) st(mean)





*Patrick better/worse*

recode Q4 1=1 2=0 3=0 4=0, gen(PatrickBetter)
tablemat PatrickBetter [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q4 1=0 2=1 3=0 4=0, gen(PatrickSame)
tablemat PatrickSame [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q4 1=0 2=0 3=1 4=0, gen(PatrickWorse)
tablemat PatrickWorse [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

*Patrick Approval*

recode app_dp 1=1 2=1 3=0 4=0 5=0 6=0, gen(ApproveDP)
tablemat ApproveDP [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode app_dp 1=0 2=0 3=0 4=1 5=1 6=0, gen(DisapproveDP)
tablemat DisapproveDP [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)


*Gov Election Trial Heats*

gen cb_vs_db=Q6a if candidateb1=="Donald Berwick"
gen cb_vs_jk=Q6a if candidateb1=="Juliette Kayeem"
gen cb_vs_mc=Q6a if candidateb1=="Martha Coakley"
gen cb_vs_sg=Q6a if candidateb1=="Steve Grossman"

replace cb_vs_db=Q6b if candidateb2=="Donald Berwick"
replace cb_vs_jk=Q6b if candidateb2=="Juliette Kayeem"
replace cb_vs_mc=Q6b if candidateb2=="Martha Coakley"
replace cb_vs_sg=Q6b if candidateb2=="Steve Grossman"

replace cb_vs_db=Q6c if candidateb3=="Donald Berwick"
replace cb_vs_jk=Q6c if candidateb3=="Juliette Kayeem"
replace cb_vs_mc=Q6c if candidateb3=="Martha Coakley"
replace cb_vs_sg=Q6c if candidateb3=="Steve Grossman"

replace cb_vs_db=Q6d if candidateb4=="Donald Berwick"
replace cb_vs_jk=Q6d if candidateb4=="Juliette Kayeem"
replace cb_vs_mc=Q6d if candidateb4=="Martha Coakley"
replace cb_vs_sg=Q6d if candidateb4=="Steve Grossman"

label define berwick 1 "Baker" 2 "Berwick" 3 "Not sure"
label define kayeem 1 "Baker" 2 "Kayeem" 3 "Not sure"
label define coakley 1 "Baker" 2 "Coakley" 3 "Not sure"
label define grossman 1 "Baker" 2 "Grossman" 3 "Not sure"

label values cb_vs_db berwick
label values cb_vs_jk kayeem
label values cb_vs_mc coakley
label values cb_vs_sg grossman

recode cb_vs_db-cb_vs_sg (4=.)

recode cb_vs_mc 1=1 2=0 3=0 4=0, gen(BakervMC)
tablemat BakervMC [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode cb_vs_mc 1=0 2=1 3=0 3=0 4=0, gen(MCvBaker)
tablemat MCvBaker [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode cb_vs_sg 1=1 2=0 3=0 4=0, gen(BakervSG)
tablemat BakervSG [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode cb_vs_sg 1=0 2=1 3=0 4=0, gen(SGvBaker)
tablemat SGvBaker [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode cb_vs_db 1=1 2=0 3=0 4=0, gen(BakervDB)
tablemat BakervDB [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode cb_vs_db 1=0 2=1 3=0 4=0, gen(DBvBaker)
tablemat DBvBaker [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode cb_vs_jk 1=1 2=0 3=0 4=0, gen(BakervJK)
tablemat BakervJK [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode cb_vs_jk 1=0 2=1 3=0 4=0, gen(JKvBaker)
tablemat JKvBaker [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)



*Senator Approval*

recode app_ew 1=1 2=1 3=0 4=0 5=0 6=0, gen(ApproveEW)
tablemat ApproveEW [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode app_ew 1=0 2=0 3=0 4=1 5=1 6=0, gen(disappEW)
tablemat disappEW [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode app_em 1=1 2=1 3=0 4=0 5=0 6=0, gen(ApproveEM)
tablemat ApproveEM [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode app_em 1=0 2=0 3=0 4=1 5=1 6=0, gen(disappEM)
tablemat disappEM [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)


*Democratic Primary Vote*

recode Q5a 1=1 2=0 3=0 4=0 5=0 6=0 7=0, gen(KayyemVote)
tablemat KayyemVote [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q5a 1=0 2=1 3=0 4=0 5=0 6=0 7=0, gen(GrossmanVote)
tablemat GrossmanVote [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q5a 1=0 2=0 3=1 4=0 5=0 6=0 7=0, gen(CoakleyVote)
tablemat CoakleyVote [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q5a 1=0 2=0 3=0 4=1 5=0 6=0 7=0, gen(BerwickVote)
tablemat BerwickVote [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

*Increased Spectators*

recode Q19 1=1 2=0 3=0 4=0, gen(ConfidentInc)
tablemat ConfidentInc [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q19 1=0 2=1 3=0 4=0, gen(SomewhatInc)
tablemat SomewhatInc [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)

recode Q19 1=0 2=0 3=1 4=0, gen(NotInc)
tablemat NotInc [aw=weight], by(region region2 gender agecat racecat incomecat educcat pid3 ideo3)  st(mean)













